/**
* @Title: AwareService.java
* @Package com.springl.aware
* @Description: TODO(用一句话描述该文件做什么)
* @author antch,861710865@qq.com
* @date 2017年7月13日 下午5:07:40
* @version V1.0
*/


package com.springl.aware;

import java.io.IOException;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;

import com.sun.org.apache.xerces.internal.impl.io.UTF8Reader;

/**
* @ClassName: AwareService
* @Description: TODO(Aware演示bean)
* @author antch,861710865@qq.com
* @date 2017年7月13日 下午5:07:40
*
*/
/*
 * 实现BeanNameAware,ResourceLoaderAware接口，
 * 获得Bean名称和资源加载的服务。
 */
@Service
public class AwareService implements BeanNameAware,ResourceLoaderAware {

	private String beanName;

	private ResourceLoader loader;

	@Override
	public void setResourceLoader(ResourceLoader resourceLoader) {
		// TODO Auto-generated method stub

		this.loader = resourceLoader;
	}

	@Override
	public void setBeanName(String arg0) {
		// TODO Auto-generated method stub

		this.beanName = arg0;
	}

	public void outputResult() {
		System.out.println("beanName的名称：：" + beanName) ;
		Resource resource =
				loader.getResource("classpath:com/springl/aware/text.txt");
		try {
			System.out.println("加载的文件的内容是：：" + IOUtils.toString(new UTF8Reader(resource.getInputStream())));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
